﻿/// <reference path="ArrayUtils.js" />
function Dictionary() {
    /// <summary>
    /// 键值对字典
    /// </summary>
    this._keys = new Array();
    this._datas = {};
    Dictionary.prototype.add = function (key, value) {
        /// <summary>
        /// 添加项，若存在KEY，则更新，若不存在KEY，则添加
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        if (!this.containKey(key)) {
            this._keys.push(key);
        }
        this._datas[key] = value;
    };
    Dictionary.prototype.get = function (key) {
        /// <summary>
        ///从字典中根据键获取值 
        /// </summary>
        /// <param name="key">键</param>
        /// <returns type="">值</returns>
        return this._datas[key];
    };
    Dictionary.prototype.containKey = function (key) {
        /// <summary>
        /// 判断字典是否存在某个键
        /// </summary>
        /// <param name="key">键</param>
        /// <returns type="">值</returns>
        return this._datas[key] != null;
    };
    Dictionary.prototype.remove = function (key) {
        if (this.containKey(key)) {
            this._keys.remove(key);
            this._datas[key] = null;
        }
    };
    Dictionary.prototype.size = function () {
        /// <summary>
        /// 获取字典长度
        /// </summary>
        /// <returns type="">长度</returns>
        return this._keys.length;
    }
}
